package codetrainning.test2;
/*
自定义方法实现比较两个int类型的数组比较 ,比较两个数组是否相等
int [] arr1 = {88,39,77,56,89,99,59,97};
int [] arr2 = {88,39,77,56,89,99,59,97};
 */
public class Demo2 {
    public static void main(String[] args) {
        int [] arr1 = {88,39,77,56,89,99,59,97};
        int [] arr2 = {88,39,77,56,89,99,59,97};
        int [] arr3 = null;
        boolean flag = false;

        try {
            flag = compare(arr1,arr2);
        } catch (NullPointerException e) {
            System.out.println("有数组为null");
        }

        System.out.println(flag);

        //异常判断
        flag = false;
        try {
            flag = compare(arr1,arr3);
        } catch (NullPointerException e) {
            System.out.println("有数组为null");
        }

        System.out.println(flag);
    }

    public static boolean compare(int[] arr, int [] brr){
        if(arr == null || brr == null){
            throw new NullPointerException();
        } else if (arr == brr) {
            return true;
        }

        if(arr.length != brr.length){
            return false;
        }

        for (int i = 0; i < arr.length; i++) {
            if(arr[i] != brr[i]){
                return false;
            }
        }
        return true;
    }
}
